In [1]:
%matplotlib inline
from matplotlib import pyplot as plt
import matplotlib.mlab as mlab
import csv
from scipy.stats import norm
import numpy as np
import scipy.stats as stats
import numpy
In [2]:
data = open('../data/data.csv', 'r').readlines()
fieldnames = ['x', 'y', 'z', 'unmasked', 'synapses']
reader = csv.reader(data)
reader.next()
rows = [[int(col) for col in row] for row in reader]
In [3]:
sorted_x = sorted(list(set([r[0] for r in rows])))
sorted_y = sorted(list(set([r[1] for r in rows])))
sorted_z = sorted(list(set([r[2] for r in rows])))
x = list([r[0] for r in rows])
y = list([r[1] for r in rows])
z = list([r[2] for r in rows])
In [4]:
real_volume = numpy.zeros((len(sorted_x), len(sorted_y), len(sorted_z)))
for r in rows:
real_volume[sorted_x.index(r[0]), sorted_y.index(r[1]), sorted_z.index(r[2])] = r[-1]
In [5]:
XYPlane = numpy.zeros((len(x), len(y)))
XZPlane = numpy.zeros((len(x), len(z)))
YZPlane = numpy.zeros((len(y), len(z)))
for row in rows:
XYPlane[row[0], row[1]] += row[-1]
XZPlane[row[0], row[2]] += row[-1]
YZPlane[row[1], row[2]] += row[-1]
In [6]:
import scipy.signal as sig
In [ ]:
AutoXYPlane = sig.correlate2d(YZPlane,YZPlane)
In [ ]:
AutoXZPlane = sig.correlate2d(XZPlane,XZPlane)
In [ ]:
AutoYZPlane = sig.correlate2d(YZPlane,YZPlane)
In [7]:
XYPlaneShrunk = numpy.zeros((len(sorted_x), len(sorted_y)))
XZPlaneShrunk = numpy.zeros((len(sorted_x), len(sorted_z)))
YZPlaneShrunk = numpy.zeros((len(sorted_y), len(sorted_z)))
for r in rows:
XYPlaneShrunk[sorted_x.index(r[0]), sorted_y.index(r[1])] += r[-1]
XZPlaneShrunk[sorted_x.index(r[0]), sorted_z.index(r[2])] += r[-1]
YZPlaneShrunk[sorted_y.index(r[1]), sorted_z.index(r[2])] += r[-1]
In [15]:
AutoXYPlane = sig.correlate2d(XYPlaneShrunk,XYPlaneShrunk)
AutoXZPlane = sig.correlate2d(XZPlaneShrunk,XZPlaneShrunk)
AutoYZPlane = sig.correlate2d(YZPlaneShrunk,YZPlaneShrunk)
plt.imshow(AutoXYPlane, interpolation='nearest', cmap = 'hot')
plt.gca().set_aspect('equal', adjustable='box')
plt.colorbar()
plt.show()
plt.imshow(AutoXZPlane, interpolation='nearest', cmap = 'hot')
plt.colorbar()
plt.axis('equal')
plt.show()
plt.imshow(AutoYZPlane, interpolation='nearest', cmap = 'hot')
plt.colorbar()
plt.show()
In [10]:
import pandas as pd
import seaborn as sns
In [46]:
frame = pd.DataFrame(AutoXYPlane)
ax = plt.axes()
sns.heatmap(frame, ax = ax)
ax.set_title('XY Plane 2D Spatial AutoCorrelation',fontsize = 20)
ax.set_xticks(np.arange(0, 101, 20))
ax.set_yticks(np.arange(0, 201, 20))
plt.xlabel("Y axis", fontsize = 20)
plt.ylabel("X axis", fontsize = 20)
plt.show()
In [48]:
frame = pd.DataFrame(AutoXZPlane)
ax = plt.axes()
sns.heatmap(frame, ax = ax)
ax.set_yticks(np.arange(0, 201, 20))
ax.set_title('XZ Plane 2D Spatial AutoCorrelation',fontsize = 20)
plt.xlabel("Z axis", fontsize = 20)
plt.ylabel("X axis", fontsize = 20)
plt.show()
In [49]:
frame = pd.DataFrame(AutoYZPlane)
ax = plt.axes()
sns.heatmap(frame, ax = ax)
ax.set_yticks(np.arange(0, 101, 20))
ax.set_title('YZ Plane 2D Spatial AutoCorrelation',fontsize = 20)
plt.xlabel("Z axis", fontsize = 20)
plt.ylabel("Y axis", fontsize = 20)
plt.show()
In [83]:
#Try auto correlation per Y layers
for i in sorted_y:
Plane = numpy.zeros((len(sorted_x), len(sorted_z)))
for r in rows:
if r[1] == i:
Plane[sorted_x.index(r[0]), sorted_z.index(r[2])] += r[-1]
AutoPlane = sig.correlate2d(Plane,Plane)
frame = pd.DataFrame(AutoPlane)
sns.heatmap(frame)
plt.show()
In [86]:
#Take into account unmasked!
XYPlaneShrunk = numpy.zeros((len(sorted_x), len(sorted_y)))
XZPlaneShrunk = numpy.zeros((len(sorted_x), len(sorted_z)))
YZPlaneShrunk = numpy.zeros((len(sorted_y), len(sorted_z)))
for r in rows:
if r[-1] != 0:
XYPlaneShrunk[sorted_x.index(r[0]), sorted_y.index(r[1])] += float(r[-1])/r[-2]
XZPlaneShrunk[sorted_x.index(r[0]), sorted_z.index(r[2])] += float(r[-1])/r[-2]
YZPlaneShrunk[sorted_y.index(r[1]), sorted_z.index(r[2])] += float(r[-1])/r[-2]
In [87]:
AutoXYPlane = sig.correlate2d(XYPlaneShrunk,XYPlaneShrunk)
AutoXZPlane = sig.correlate2d(XZPlaneShrunk,XZPlaneShrunk)
AutoYZPlane = sig.correlate2d(YZPlaneShrunk,YZPlaneShrunk)
plt.imshow(AutoXYPlane, interpolation='nearest', cmap = 'hot')
plt.colorbar()
plt.show()
plt.imshow(AutoXZPlane, interpolation='nearest', cmap = 'hot')
plt.colorbar()
plt.show()
plt.imshow(AutoYZPlane, interpolation='nearest', cmap = 'hot')
plt.colorbar()
plt.show()
In [ ]: